import Vue from 'vue';

import 'normalize.css/normalize.css'; // A modern alternative to CSS resets

import ElementUI from 'element-ui';
import 'element-ui/lib/theme-chalk/index.css';
import locale from 'element-ui/lib/locale/lang/zh-CN'; // lang i18n 中文

import '@/styles/common.css';
import '@/styles/index.scss'; // global css

import App from './App';
import router from './router';
import store from './store';

import i18n from './lang'; // Internationalization
import '@/icons'; // icon
import '@/permission'; // permission control
import VueClipboard from 'vue-clipboard2';
import pickPlugin from '@/plugins/pick';
import ttPlugin from '@/plugins/tt';
import exportDataPlugin from '@/plugins/export_data';
import transformer from '@/plugins/transformer';
import dtFilters from '@/filters/dt';
import DateRangePicker from '@/components/DateRangePicker';
import SearchForm from '@/components/SearchForm';
import LoadingButton from '@/components/LoadingButton.vue';

if (process.env.TARGET_ENV !== 'dev' && process.env.TARGET_ACTION === 'build') {
  require('@/utils/sentry');
}

VueClipboard.config.autoSetContainer = true;
Vue.use(VueClipboard);
Vue.use(ElementUI, {
  locale,
  zIndex: 1000,
  i18n: (key, value) => i18n.t(key, value)
});

Vue.component('date-range-picker', DateRangePicker);
Vue.component('search-form', SearchForm);
Vue.component('l-button', LoadingButton);

Vue.use(pickPlugin);
Vue.use(ttPlugin);
Vue.use(exportDataPlugin);
Vue.use(transformer);

Object.keys(dtFilters).forEach(k => {
  Vue.filter(k, dtFilters[k]);
});

import echarts from 'echarts';

import 'echarts/extension/bmap/bmap';
Vue.prototype.$echarts = echarts;

//  设置时间全局过滤器
import timeHandleObj from './utils/timeHandle.js';
Vue.filter('fmtdate', function(timestamp) {
  return timeHandleObj.timeHandle(timestamp);
});

// 保留几位小数
import textFormatting from './utils/textFormatting.js';
Vue.filter('numToFixed', function(num, length) {
  return textFormatting.numToFixed(num, length);
});

Vue.config.productionTip = false;

new Vue({
  el: '#app',
  router,
  store,
  i18n,
  render: h => h(App)
});
